import torch.nn as nn


class LeNet(nn.Module):
    def __init__(self):
        super().__init__()
        # input: 1*28*28
        self.layer1 = nn.Sequential(
            nn.Conv2d(
                in_channels=1,
                out_channels=6,
                kernel_size=5,
                stride=1
            ),
            nn.ReLU(),
            # 6*24*24
            nn.AvgPool2d(
                kernel_size=2,
                stride=2
            )
        )

        # 6*12*12
        self.layer2 = nn.Sequential(
            nn.Conv2d(
                in_channels=6,
                out_channels=16,
                kernel_size=5,
                stride=1
            ),
            nn.ReLU(),
            # 16*8*8
            nn.MaxPool2d(
                kernel_size=2,
                stride=2
            )
        )

        # 16*4*4
        self.fc = nn.Sequential(
            nn.Linear(256, 120),
            nn.Linear(120, 84),
            nn.Linear(84, 10)
        )

    def forward(self, x):
        x = self.layer1(x)
        x = self.layer2(x)
        x = self.fc(x.view(x.size(0), -1))
        return x
